package com.zzyl.controller.customer;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.NursingProjectPageDTO;
import com.zzyl.entity.Reservation;
import com.zzyl.service.ReservationService;
import com.zzyl.vo.ReservationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "预约接口")
public class ReservationController extends BaseController {

    @Autowired
    private ReservationService reservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult getCancelledCount(){
       Integer number =  reservationService.getCancelledCount();
        return  success(number);
    }

    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public ResponseResult countByTime(Long time){
        List<Map<String,Object>> mapList = reservationService.countByTime(time);
        return success(mapList);
    }

    @PostMapping
    @ApiOperation("新增预约")
    public ResponseResult insert(@RequestBody Reservation reservation){
        reservationService.insert(reservation);
        return success();
    }

    @GetMapping("/page")
    @ApiOperation("预约分页条件查询")
    public ResponseResult pageCondition(NursingProjectPageDTO nursingProjectPageDTO){
       PageResponse<ReservationVo> pageResponse = reservationService.pageCondition(nursingProjectPageDTO);
        return success(pageResponse);
    }

    @PutMapping("{id}/cancel")
    @ApiOperation("取消")
    public ResponseResult cancel(@PathVariable Long id){
        reservationService.cancel(id);
        return success();
    }
}
